package com.bamboo.framework.framework.security.controller;


import com.bamboo.framework.framework.security.entity.Menu;
import com.bamboo.framework.framework.security.service.IMenuService;
import com.bamboo.framework.common.format.ReturnMsg;
import com.bamboo.framework.common.enums.Status;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author 郭晴
 * @since 2018-12-19
 */
@RestController
@RequestMapping("/menu")
public class MenuController {


    @Resource
    private IMenuService iMenuService;

    /**
     * 获取所有菜单信息
     */
    @GetMapping("getAllMenus")
    public ReturnMsg getMenus() {
        return  new ReturnMsg(Status.SUCCESS,iMenuService.selectMenusAll());
    }
    /**
     * 获取所有子菜单信息
     */
    @GetMapping("getSubmenuAll")
    public ReturnMsg getSubmenuAll() {
        return  new ReturnMsg(Status.SUCCESS,iMenuService.selectSubmenuAll());
    }


    /**
     * 根据id获取菜单信息
     */
    @GetMapping("getMenuById")
    public ReturnMsg getMenuById(@RequestParam Integer id) {
        return  new ReturnMsg(Status.SUCCESS,iMenuService.getById(id));
    }

    /**
     * 删除菜单
     */
    @PostMapping("deleteMenu")
    public ReturnMsg deleteMenu(@RequestParam Integer id) {
        boolean deleteMenuById = iMenuService.deleteMenuById(id);
        if(deleteMenuById){
              return  new ReturnMsg(Status.SUCCESS,"删除菜单成功");
        }
        return  new ReturnMsg(Status.ERROR,"删除菜单失败");

    }


    /**
     * 更新或插入菜单
     */
    @PostMapping("saveOrUpdateMenu")
    public ReturnMsg saveMenu(@RequestBody Menu menu) {
        return  iMenuService.saveMenu(menu);
    }


}
